package ro.ubbcluj.cs.damate.services;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import ro.ubbcluj.cs.damate.persistence.entities.Role;
import ro.ubbcluj.cs.damate.persistence.repository.RoleRepository;

import java.util.List;

/**
 * @author Lóránd Fazakas (lorand)
 *         Date: 5/10/12
 *         Time: 9:49 PM
 */
@Service
public class RoleService {

    @Autowired
    private RoleRepository roleRepository;

    @Transactional
    public void create(Role transientGroup) {
        roleRepository.save(transientGroup);
    }

    public List<Role> findAll() {
        return roleRepository.findAll();
    }

    public Role findRoleByName(String roleName) {
        List<Role> roles = roleRepository.findByRoleName(roleName);
        return (roles != null && !roles.isEmpty()) ? roles.get(0) : null;
    }
}
